package com.nf.health.app.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.utils.DateUtil;
import com.nf.health.app.utils.Util;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

public class DataDetailsHistoryAdapter extends BaseAdapter {

	private ArrayList<String> yValues  ;
	private  ArrayList<String> xValues;
	private Context context;
	public DataDetailsHistoryAdapter (Context context,ArrayList<String> yValues,ArrayList<String> xValues){
		this.context = context;
		this.yValues = yValues;
		this.xValues = xValues;
	}
	@Override
	public int getCount() {
		return yValues.size();
	}

	@Override
	public Object getItem(int position) {
		return yValues.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressLint("ResourceAsColor")
	@Override
	public View getView(int position, View arg1, ViewGroup arg2) {
		ViewHolder holder = null;
		if (arg1 == null) {
			holder = new ViewHolder();
			arg1 = View.inflate(context, R.layout.item_ddh, null);
			holder.tv_ddh_time = (TextView) arg1.findViewById(R.id.tv_ddh_timeId);
			holder.tv_ddh_data = (TextView) arg1.findViewById(R.id.tv_ddh_dataId);
			holder.ll_dd = (LinearLayout) arg1.findViewById(R.id.ll_ddhId);
			arg1.setTag(holder);
		} else {
			holder = (ViewHolder) arg1.getTag();
		}
		if(position == 0){
			holder.tv_ddh_time.setText(xValues.get(position));
			holder.tv_ddh_data.setText(yValues.get(position));
		}else{
			holder.tv_ddh_time.setText(DateUtil.dateToString(new Date(Long.parseLong(xValues.get(position))), "yyyy-MM-dd HH:mm:ss"));
			holder.tv_ddh_data.setText(yValues.get(position));
		}
		if (position==0) {
			holder.tv_ddh_time.setTextColor(Color.WHITE);
			holder.tv_ddh_data.setTextColor(Color.WHITE);
			holder.ll_dd.setBackgroundColor(Color.parseColor("#22D5DA"));
		} else {
			holder.tv_ddh_time.setTextColor(Color.BLACK);
			holder.tv_ddh_data.setTextColor(Color.BLACK);
			holder.ll_dd.setBackgroundColor(Color.WHITE);
		}
		return arg1;
	}
	static class ViewHolder{
		LinearLayout ll_dd;
		TextView tv_ddh_time;
		TextView tv_ddh_data;
	}
}
